home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 7 / Amiga Format AFCD07 (Dec 1996, Issue 91).iso / serious / shareware / programming / gamesmaster / source / asm / screendemos / doublebuffer.s < prev    next >
Encoding:
Text File  |  1996-09-11  |  3.8 KB  |  127 lines

  1. ;Double Buffering
  2. ;----------------
  3. ;This just shows how to double buffer the screen.  You can also try out
  4. ;triple buffering just by changing the DBLBUFFER flag to TPLBUFFER in the
  5. ;ScreenStruct.
  6. ;
  7. ;Notice that this thing does in fact fully multi-task (no forbid/permit)!
  8. ;Instead we set our task priority to be a little higher than any other tasks
  9. ;-- if we didn't do this sometimes our frames could be stalled (try removing
  10. ;the SetUserPri and watch the demo again).
  11.  
  12.     opt    o+
  13.  
  14.     INCLUDE    "exec/exec_lib.i"
  15.     INCLUDE    "games/games_lib.i"
  16.     INCLUDE    "games/games.i
  17.  
  18. CALL    MACRO
  19.     jsr    _LVO\1(a6)
  20.     ENDM
  21.  
  22.     SECTION    "DoubleBuffer",CODE
  23.  
  24. ;===========================================================================;
  25. ;                             INITIALISE DEMO
  26. ;===========================================================================;
  27.  
  28. Start:    MOVEM.L    A0-A6/D1-D7,-(SP)
  29.     move.l    ($4).w,a6
  30.     lea    GMS_Name(pc),a1
  31.     moveq    #$00,d0
  32.     CALL    OpenLibrary
  33.     move.l    d0,GMS_Base
  34.     beq.s    Quit
  35.  
  36.     move.l    GMS_Base(pc),a6          ;Set the task priority to a
  37.     CALL    SetUserPri               ;user-selected level.
  38.  
  39.     lea    ScreenStruct(pc),a0      ;Add screen for use.
  40.     CALL    Add_Screen
  41.     tst.l    d0
  42.     bne.s    Error
  43.  
  44.     lea    Picture(pc),a1           ;a1 = Picture struct.
  45.     move.l    SS_MemPtr1(a0),PIC_Data(a1)
  46.     lea    PicFile(pc),a0           ;a0 = Picture file.
  47.     CALL    LoadPic
  48.     tst.w    d0
  49.     bne.s    ReturnToDOS
  50.  
  51.     lea    ScreenStruct(pc),a0      ;Now show the screen/pic.
  52.     CALL    Show_Screen
  53.  
  54. ;===========================================================================;
  55. ;                                MAIN LOOP
  56. ;===========================================================================;
  57.  
  58. Loop:    CALL    Wait_OSVBL               ;Nice VBL wait for multi-tasking.
  59.     CALL    SwapBuffers
  60.     moveq    #JPORT1,d0               ;Port 1 (mouse)
  61.     moveq    #JT_ZBXY,d1
  62.     CALL    Read_JoyPort
  63.     btst    #MB_LMB,d0
  64.     beq.s    Loop
  65.  
  66. ;===========================================================================;
  67. ;                              RETURN TO DOS
  68. ;===========================================================================;
  69.  
  70. ReturnToDOS:
  71.     move.l    GMS_Base(pc),a6
  72.     lea    ScreenStruct(pc),a0
  73.     CALL    Delete_Screen            ;Give back screen memory etc.
  74. Error:    move.l    GMS_Base(pc),a1
  75.     move.l    ($4).w,a6
  76.     CALL    CloseLibrary
  77. Quit:    MOVEM.L    (SP)+,A0-A6/D1-D7
  78.     moveq    #$00,d0
  79.     rts
  80.  
  81. ;===========================================================================;
  82. ;                                  DATA
  83. ;===========================================================================;
  84.  
  85. GMS_Name:
  86.     dc.b    "games.library",0
  87.     even
  88. GMS_Base:
  89.     dc.l    0
  90.  
  91. AMT_PLANES =    5
  92.  
  93. ScreenStruct:
  94.     dc.l    "GSV1",0          ;Structure Version & Stats.
  95.     dc.l    0,0,0             ;Screen_Mem1/2/3
  96.     dc.l    0                 ;Screen link.
  97.     dc.l    Palette           ;Address of screen palette
  98.     dc.l    0                 ;Address of rasterlist.
  99.     dc.l    0                 ;Amt of colours in palette.
  100.     dc.w    320,256,320,256   ;Screen & Pic Height/Width.
  101.     dc.w    AMT_PLANES        ;Amt of planes
  102.     dc.w    0,0               ;X/Y screen offset
  103.     dc.w    0,0               ;X/Y picture offset
  104.     dc.l    DBLBUFFER         ;Special attributes.
  105.     dc.w    LORES             ;Screen mode.
  106.     dc.b    INTERLEAVED       ;Screen type
  107.     dc.b    0                 ;Reserved.
  108.     even
  109.  
  110. Palette    dc.w    $0000,$0130,$0FCB,$0FA9,$0D88,$0965,$0644,$0211
  111.     dc.w    $0400,$0444,$0FF0,$0432,$0CC0,$0150,$0501,$0880
  112.     dc.w    $0261,$0271,$0382,$0492,$05A3,$05B4,$0677,$06C4
  113.     dc.w    $0788,$09AA,$0BCC,$0801,$0901,$0A02,$0701,$0601
  114.  
  115. Picture    dc.l    "PCV1",0           ;Version header.
  116.     dc.l    0                  ;Source data.
  117.     dc.w    320,256            ;Width, Height.
  118.     dc.w    AMT_PLANES         ;Amount of Planes.
  119.     dc.l    32                 ;Amount of colours.
  120.     dc.l    Palette            ;Source palette (remap).
  121.     dc.w    LORES              ;Screen mode.
  122.     dc.w    INTERLEAVED        ;Destination
  123.     dc.l    0                  ;Parameters.
  124.  
  125. PicFile    dc.b    "GAMESLIB:data/IFF.Pic320",0
  126.     even
  127.